﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Web.UI;
using Org.Eurekaa.DNJ.Settings;

namespace Org.Eurekaa.DNJ.UI.DNJSettings
{
    [TypeConverter(typeof(ExpandableObjectConverter))]
    [Serializable()]
    public class DNJTabsEvents : GenericSettingsObject
    {

        [Description("This event is triggered when clicking a tab.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Select
        {
            get { return Get<UIEventFunction>("select"); }
            set { this["select"] = value; }
        }

        [Description("This event is triggered after the content of a remote tab has been loaded.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Load
        {
            get { return Get<UIEventFunction>("load"); }
            set { this["load"] = value; }
        }

        [Description("This event is triggered when a tab is shown.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Show
        {
            get { return Get<UIEventFunction>("show"); }
            set { this["show"] = value; }
        }

        [Description("This event is triggered when a tab is added.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Add
        {
            get { return Get<UIEventFunction>("add"); }
            set { this["add"] = value; }
        }

        [Description("This event is triggered when a tab is removed.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Remove
        {
            get { return Get<UIEventFunction>("remove"); }
            set { this["remove"] = value; }
        }

        [Description("This event is triggered when a tab is enabled.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Enable
        {
            get { return Get<UIEventFunction>("enable"); }
            set { this["enable"] = value; }
        }

        [Description("This event is triggered when a tab is disabled.")]
        [DefaultValue(""), NotifyParentProperty(true), RefreshProperties(RefreshProperties.Repaint)]
        [PersistenceMode(PersistenceMode.InnerProperty), DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
        public UIEventFunction Disable
        {
            get { return Get<UIEventFunction>("disable"); }
            set { this["disable"] = value; }
        }



        public DNJTabsEvents()
        {
            this["select"] = new UIEventFunction();
            this["load"] = new UIEventFunction();
            this["show"] = new UIEventFunction();
            this["add"] = new UIEventFunction();
            this["remove"] = new UIEventFunction();
            this["enable"] = new UIEventFunction();
            this["disable"] = new UIEventFunction();
        }

        public string GetDefaultEventsScript()
        {
            String evtScript = String.Empty;
            foreach (UIEventFunction evt in Settings.Values)
            {
                if (!string.IsNullOrEmpty(evt.Name))
                {
                    evtScript += "if (!window." + evt.Name.Trim() + "){" + evt.Name.Trim() + " = new Function(\"return dnjDefaultEvent('" + evt.Name.Trim() + "')\");}";
                }
            }

            return evtScript;
        }
        public override string ToString()
        {
            return base.ToString();
        }


        public override void PrepareJSON()
        {
            
        }
    }

}
